package model;

import java.io.Serializable;

import javax.persistence.*;

import org.eclipse.persistence.annotations.Mutable;

import dtos.MeanOfTransportationDTO;
import dtos.PersonalizedTPDTO;
import dtos.PredefinedTPDTO;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;


/**
 * The persistent class for the meanOfTransportation database table.
 * 
 */
@Entity
@NamedQuery(name="MeanOfTransportation.findAll", query="SELECT m FROM MeanOfTransportation m")
public class MeanOfTransportation implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	private int transportationID;

	private int cost;


	@Mutable(true)
	private String departureTime;

	private int duration;

	//bi-directional many-to-one association to TransportationType
	@ManyToOne
	@JoinColumn(name="transportationTypeID")
	private TransportationType transportationType;

	//bi-directional many-to-one association to Trip
	@ManyToOne
	@JoinColumn(name="tripID")
	private Trip trip;

	//bi-directional many-to-one association to PersonalizedTP
	@OneToMany(mappedBy="meanOfTransportation1")
	private List<PersonalizedTP> personalizedTps1;

	//bi-directional many-to-one association to PersonalizedTP
	@OneToMany(mappedBy="meanOfTransportation2")
	private List<PersonalizedTP> personalizedTps2;

	//bi-directional many-to-one association to PredefinedTP
	@OneToMany(mappedBy="meanOfTransportation1")
	private List<PredefinedTP> predefinedTps1;

	//bi-directional many-to-one association to PredefinedTP
	@OneToMany(mappedBy="meanOfTransportation2")
	private List<PredefinedTP> predefinedTps2;

	public MeanOfTransportation() {
	}
	
	public MeanOfTransportation(MeanOfTransportationDTO mean){
		this.cost = mean.getCost();
		this.departureTime = mean.getDepartureTime();
		this.duration = mean.getDuration();
		this.transportationID = mean.getTransportationID();
	}
	
	public MeanOfTransportationDTO getDTO(){
		MeanOfTransportationDTO m = new MeanOfTransportationDTO();
		m.setCost(this.cost);
		m.setDepartureTime(this.departureTime);
		m.setDuration(this.duration);
		//m.setPersonalizedTps1(this.getPersonalizedTps1DTO());
		//m.setPersonalizedTps2(this.getPersonalizedTps2DTO());
		//m.setPredefinedTps1(this.getPredefinedTps1DTO());
		//m.setPredefinedTps2(this.getPredefinedTps2DTO());
		m.setTransportationID(this.transportationID);
		m.setTransportationType(this.transportationType.getDTO());
		m.setTrip(this.trip.getDTO());
		
		return m;
	}

	public int getTransportationID() {
		return this.transportationID;
	}

	public void setTransportationID(int transportationID) {
		this.transportationID = transportationID;
	}

	public int getCost() {
		return this.cost;
	}

	public void setCost(int cost) {
		this.cost = cost;
	}

	public String getDepartureTime() {
		return this.departureTime;
	}

	public void setDepartureTime(String departureTime) {
		this.departureTime = departureTime;
	}

	public int getDuration() {
		return this.duration;
	}

	public void setDuration(int duration) {
		this.duration = duration;
	}

	public TransportationType getTransportationType() {
		return this.transportationType;
	}

	public void setTransportationType(TransportationType transportationType) {
		this.transportationType = transportationType;
	}

	public Trip getTrip() {
		return this.trip;
	}

	public void setTrip(Trip trip) {
		this.trip = trip;
	}

	public List<PersonalizedTP> getPersonalizedTps1() {
		return this.personalizedTps1;
	}
	
	public List<PersonalizedTPDTO> getPersonalizedTps1DTO() {
		List<PersonalizedTPDTO> res = new LinkedList<PersonalizedTPDTO>();
		for (PersonalizedTP p : this.personalizedTps1){
			res.add(p.getDTO());
		}
		return res;
		
	}

	public void setPersonalizedTps1(List<PersonalizedTP> personalizedTps1) {
		this.personalizedTps1 = personalizedTps1;
	}

	public PersonalizedTP addPersonalizedTps1(PersonalizedTP personalizedTps1) {
		getPersonalizedTps1().add(personalizedTps1);
		personalizedTps1.setMeanOfTransportation1(this);

		return personalizedTps1;
	}

	public PersonalizedTP removePersonalizedTps1(PersonalizedTP personalizedTps1) {
		getPersonalizedTps1().remove(personalizedTps1);
		personalizedTps1.setMeanOfTransportation1(null);

		return personalizedTps1;
	}

	public List<PersonalizedTP> getPersonalizedTps2() {
		return this.personalizedTps2;
	}
	
	public List<PersonalizedTPDTO> getPersonalizedTps2DTO() {
		List<PersonalizedTPDTO> res = new LinkedList<PersonalizedTPDTO>();
		for (PersonalizedTP p : this.personalizedTps2){
			res.add(p.getDTO());
		}
		return res;
		
	}

	public void setPersonalizedTps2(List<PersonalizedTP> personalizedTps2) {
		this.personalizedTps2 = personalizedTps2;
	}

	public PersonalizedTP addPersonalizedTps2(PersonalizedTP personalizedTps2) {
		getPersonalizedTps2().add(personalizedTps2);
		personalizedTps2.setMeanOfTransportation2(this);

		return personalizedTps2;
	}

	public PersonalizedTP removePersonalizedTps2(PersonalizedTP personalizedTps2) {
		getPersonalizedTps2().remove(personalizedTps2);
		personalizedTps2.setMeanOfTransportation2(null);

		return personalizedTps2;
	}

	public List<PredefinedTP> getPredefinedTps1() {
		return this.predefinedTps1;
	}
	
	
	public List<PredefinedTPDTO> getPredefinedTps1DTO() {
		List<PredefinedTPDTO> res = new LinkedList<PredefinedTPDTO>();
		for (PredefinedTP p : this.predefinedTps1){
			res.add(p.getDTO());
		}
		return res;
		
	}

	public void setPredefinedTps1(List<PredefinedTP> predefinedTps1) {
		this.predefinedTps1 = predefinedTps1;
	}

	public PredefinedTP addPredefinedTps1(PredefinedTP predefinedTps1) {
		getPredefinedTps1().add(predefinedTps1);
		predefinedTps1.setMeanOfTransportation1(this);

		return predefinedTps1;
	}

	public PredefinedTP removePredefinedTps1(PredefinedTP predefinedTps1) {
		getPredefinedTps1().remove(predefinedTps1);
		predefinedTps1.setMeanOfTransportation1(null);

		return predefinedTps1;
	}

	public List<PredefinedTP> getPredefinedTps2() {
		return this.predefinedTps2;
	}
	
	public List<PredefinedTPDTO> getPredefinedTps2DTO() {
		List<PredefinedTPDTO> res = new LinkedList<PredefinedTPDTO>();
		for (PredefinedTP p : this.predefinedTps2){
			res.add(p.getDTO());
		}
		return res;
		
	}

	public void setPredefinedTps2(List<PredefinedTP> predefinedTps2) {
		this.predefinedTps2 = predefinedTps2;
	}

	public PredefinedTP addPredefinedTps2(PredefinedTP predefinedTps2) {
		getPredefinedTps2().add(predefinedTps2);
		predefinedTps2.setMeanOfTransportation2(this);

		return predefinedTps2;
	}

	public PredefinedTP removePredefinedTps2(PredefinedTP predefinedTps2) {
		getPredefinedTps2().remove(predefinedTps2);
		predefinedTps2.setMeanOfTransportation2(null);

		return predefinedTps2;
	}

	public boolean isFromTo(String departurePlace, String arrivalPlace) {

		return ((this.trip.getDeparturePlace().equals(departurePlace))&&(this.trip.getArrivalPlace().equals(arrivalPlace)));
	}

}